package com.laijiale.controller;

import com.laijiale.dto.NoticeInsertDTO;
import com.laijiale.dto.NoticePageDTO;
import com.laijiale.dto.NoticeUpdateDTO;
import com.laijiale.entity.Notice;
import com.laijiale.vo.NoticeSimpleListVO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.aspectj.weaver.ast.Not;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.laijiale.entity.Notice;
import com.laijiale.service.NoticeService;

import java.util.List;

/**
 * 通知表 控制层。
 *
 * @author laijiale
 * @since 2024-12-22
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;


    @Operation(summary ="新增－ 单条",description ="新增一条通知记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody NoticeInsertDTO dto) {
        return noticeService.insert(dto);
    }
    @Operation(summary="查询－ 单条",description="按主键查询一条通知记录")
    @GetMapping("select/{id}")
    public Notice select(@PathVariable("id") Long id) {
        return noticeService.select(id);
    }
    @Operation(summary="查询－ 查询前N条",description="按主键查询前N通知记录")
    @GetMapping("top/{N}")
    public List<Notice> top(@PathVariable("N") Long N) {
        return noticeService.top(N);
    }
    @Operation(summary ="查询－ 简单全查",description="查询全部通知记录")
    @GetMapping("simpleList")
    public List<NoticeSimpleListVO> simpleList() {
        return noticeService.simpleList();
    }
    @Operation(summary="查询－ 分页",description ="分页查询通知记录")
    @GetMapping("page")
    public Page<Notice> page(@Validated NoticePageDTO dto) {
        return noticeService.page(dto);
    }

    @Operation(summary="修改－单条",description ="按主键修改一条通知记录")
    @PutMapping("update")
    public boolean update(@RequestBody NoticeUpdateDTO dto) {
        return noticeService.update(dto);
    }
    @Operation(summary="删除－ 单条",description="按主键删除一条通知记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return noticeService.delete(id);
    }
    @Operation(summary="删除－ 批量",description ="按主键批量删除通知记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return noticeService.deleteBatch(ids);
    }

}
